package com.guigu.www.controller.yinBo;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.guigu.www.dao.bean.TCheckgroup;
import com.guigu.www.dao.bean.TCheckgroupCheckitem;
import com.guigu.www.dao.bean.TCheckitem;
import com.guigu.www.dao.bean.TSetmealCheckgroup;
import com.guigu.www.service.TCheckgroupCheckitemService;
import com.guigu.www.service.TCheckitemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 检查分组关联表 前端控制器
 * </p>
 *
 * @author abo
 * @since 2021-06-17
 */
@RestController
@CrossOrigin
public class TCheckgroupCheckitemController {

    @Autowired
    TCheckgroupCheckitemService tCheckgroupCheckitemService;

    @Autowired
    TCheckitemService tCheckitemService;


    @PostMapping("/tCheckgroupCheckitem")
    public Map<String, List<TCheckitem>> q(@RequestBody List<TCheckgroup> list){

        List<Integer> checkgroupIdsList = new ArrayList<Integer>();

        for (TCheckgroup x :list) {
            checkgroupIdsList.add(x.getId());
        }

        Map<String, List<TCheckitem>> map = new HashMap<String, List<TCheckitem>>();

        for (int x=0;x<checkgroupIdsList.size();x++){
            Wrapper<TCheckitem> wrapper=new EntityWrapper<TCheckitem>();
            wrapper.where("id in (\n" +
                            "select  checkitem_id  from t_checkgroup_checkitem  where checkgroup_id in\n" +
                            "\t(select  id from t_checkgroup where id ="+checkgroupIdsList.get(x)+"))");

            List<TCheckitem> tCheckitems = tCheckitemService.selectList(wrapper);
            map.put(checkgroupIdsList.get(x).toString(),tCheckitems);
        }
        return map;
       /* Wrapper<TCheckgroupCheckitem> wrapper = new EntityWrapper<TCheckgroupCheckitem>();

        wrapper.in("checkgroup_id",list);

        List<TCheckgroupCheckitem> TCheckgroupCheckitems = tCheckgroupCheckitemService.selectList(wrapper);
        System.out.println(TCheckgroupCheckitems);

        ArrayList<Integer> ids = new ArrayList<Integer>();
        for (TCheckgroupCheckitem x :TCheckgroupCheckitems){
            ids.add(x.getCheckitemId());
        }
        System.out.println(ids);

        Wrapper<TCheckitem> idsWrapper = new EntityWrapper<TCheckitem>();
        idsWrapper.in("id",ids);
        List<TCheckitem> tCheckitems = tCheckitemService.selectList(idsWrapper);
        System.out.println(tCheckitems);*/
    }
}

